import numpy as np
def quorem(A, B, var):
    """
    Returns :quorem(A,B,var) divides A by B and returns the quotient Q and remainder R of the division, such that A = Q*B + R. This syntax regards A and B as polynomials in the variable var.
    If A and B are matrices, quorem performs elements-wise division, using var as a variable. It returns the quotient Q and remainder R of the division, such that A = Q.*B + R.

    Args:
       Scalar or  Matrix inputs

    Returns:
        Scalar or  Matrix  divides A by B and returns the quotient Q and remainder R of the division
    """
    if isinstance(A, int) and isinstance(B, int):
        Q = A // B
        R = A % B
    elif (isinstance(A, (tuple,list)) and isinstance(B, (tuple,list))) or type(A) == np.ndarray and type(B) == np.ndarray:
        Q = A // B
        R = A - Q * B
    else:
        raise TypeError("Input type not supported.")
        return
    return Q, R

def test01():
    # Scalar inputs
    assert quorem(7, 3, 'x') == (2, 1)
    assert quorem(-7, 3, 'x') == (-3, 2)
    assert quorem(7, -3, 'x') == (-3, -2)
    assert quorem(-7, -3, 'x') == (2, -1)
def test02():
    # Matrix inputs
    A = np.array([[1, 2], [3, 4]])
    B = np.array([[2, 1], [1, 2]])
    Q = np.array([[0, 2], [3, 1]])
    R = np.array([[1, 0], [0, 2]])
    assert np.all(quorem(A, B, 'x')) == np.all((Q, R))
test01()
test02()
